package com.smartmap.chat;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.smartmap.R;


public class GroupDisplayAdapter extends BaseExpandableListAdapter{
	List<UserGroup> userList;
    private Context context; 
    LayoutInflater inflater; 
     
    public GroupDisplayAdapter(Context context,List<UserGroup> list){ 
        this.context=context; 
        inflater = LayoutInflater.from(context); 
        this.userList=list; 
    } 
    
    public GroupDisplayAdapter(LayoutInflater inflater,List<UserGroup> list){ 
        this.inflater = inflater; 
        this.userList=list; 
    } 
    public Object getChild(int groupPosition, int childPosition) { 
    	return userList.get(groupPosition).getUserList().get(childPosition);
    } 
 
    public long getChildId(int groupPosition, int childPosition) { 
        return childPosition; 
    } 
 
    /**
     * 显示分组下列表信息
     */
    public View getChildView(int groupPosition, int childPosition, boolean arg2, View convertView, 
            ViewGroup arg4) { 
        convertView = inflater.inflate(R.layout.buddy_listview_child_item, null); 
        TextView nickTextView=(TextView) convertView.findViewById(R.id.buddy_listview_child_nick); 
        TextView moodSignatureView = (TextView) convertView.findViewById(R.id.moodSignature);
        UserInformation userInfo = (UserInformation) getChild(groupPosition, childPosition);
        nickTextView.setText(userInfo.getNickname()); 
        moodSignatureView.setText(userInfo.getMoodSignature());
        return convertView; 
    } 
 
    public int getChildrenCount(int groupPosition) { 
        return userList.get(groupPosition).getUserList().size(); 
    } 
 
    public Object getGroup(int groupPosition) { 
        return userList.get(groupPosition); 
    } 
 
    public int getGroupCount() { 
        return userList.size(); 
    } 
 
    public long getGroupId(int groupPosition) { 
        return groupPosition; 
    } 
 
    /**
     * 显示分组信息
     */
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup arg3) { 
        convertView = inflater.inflate(R.layout.buddy_listview_group_item, null); 
        TextView groupNameTextView=(TextView) convertView.findViewById(R.id.buddy_listview_group_name); 
        TextView groupNumTextView = (TextView) convertView.findViewById(R.id.listview_group_num);
        ImageView image = (ImageView) convertView.findViewById(R.id.buddy_listview_image); 
        
        UserGroup userGroup = (UserGroup)getGroup(groupPosition);
        groupNameTextView.setText(userGroup.getGroupName()); 
        groupNumTextView.setText(String.valueOf(userGroup.getGroupNum()));
        /*image.setImageResource(R.drawable.group_unfold_arrow); 
        //更换展开分组图片  
        if(!isExpanded){ 
            image.setImageResource(R.drawable.group_fold_arrow); 
        } */
        return convertView; 
    } 
 
    public boolean hasStableIds() { 
        return true; 
    } 
    // 子选项是否可以选择   
    public boolean isChildSelectable(int arg0, int arg1) { 
        // TODO Auto-generated method stub  
        return true; 
    } 
}
